from ui import ImageProcessorUI
from .base import ImageProcessor
from PIL import Image, ImageOps

class MirrorProcessor(ImageProcessor):
    def process(self, image: Image.Image, **kwargs) -> Image.Image:
        """
        对图像进行镜像翻转。
        参数:
        - image: 输入图像 (PIL Image)
        - direction: 翻转方向 ("horizontal" 水平 或 "vertical")
        返回:
        - Image.Image: 处理后的图像
        """
        direction = kwargs.get("direction", "horizontal")
        if direction == "horizontal":
            return ImageOps.mirror(image)
        elif direction == "vertical":
            return ImageOps.flip(image)
        else:
            raise ValueError(f"未知的镜像方向: {direction}")

    def get_ui_parameters(self, ui: "ImageProcessorUI") -> dict:
        """
        从 UI 获取参数
        """
        try:
            direction = ui.mirror_direction_var.get()
            return {
                "direction": direction
            }
        except Exception as e:
            ui.show_error(f"获取参数失败: {e}")
            return {}